// pages/organization/show.js
const util = require('../../utils/util.js');
const apiUrl = require('../../utils/apiUrl.js');
var http = require('../../utils/httpHelper.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    winWidth: 0,
    winHeight: 0,
    fontSize: 16,
    id: 0,
    detail: {},
    loaddinghidden: true,
    showLoading: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var id = options.id;
    if (!id) {
      wx.showModal({
        title: '加载失败！',
        success: function (res) {
          if (res.confirm) {
            wx.navigateBack();
          }
        }
      })
      return;
    }

    /**
     * 获取系统信息
     */
    wx.getSystemInfo({

      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });

    // 显示 loading
    that.setData({
      id: id,
      loaddinghidden: false
    });

    that.loadData();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
  },
  loadData: function () {
    var that = this;
    var parameter = {};
    parameter['id'] = that.data.id;
    //获取数据
    http.ApiGet(apiUrl.UrlOrgDetail, parameter, function (res) {
      wx.stopPullDownRefresh() //停止下拉刷新
      if (res.result.errorCode == 1) {

        that.setData({
          loaddinghidden: true,
          detail: res.data,
        });

      } else {
        wx.showModal({
          title: res.result.errorMessage
        });
      }
    });
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.loadData();
  },
  imageTap: function (e) {
    var val = e.currentTarget.dataset.val;
    wx.previewImage({
      current: val,
      urls: this.data.detail.images
    })
  },
})